package com.finance.system.controller;

import com.alibaba.druid.util.StringUtils;
import com.finance.base.exception.BaseException;
import com.finance.framework.controller.BaseController;
import com.finance.framework.controller.Result;
import com.finance.framework.lang.BeanUtils;
import com.finance.framework.lang.Page;
import com.finance.framework.lang.PageResultBO;
import com.finance.report.bean.pojo.LogisticsData;
import com.finance.report.bean.pojo.LogisticsErrorList;
import com.finance.report.bean.pojo.LogisticsErrorLog;
import com.finance.report.request.LogisticsErrorLogListReq;
import com.finance.report.service.ILogisticsErrorLogService;
import com.finance.util.DateUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import java.text.ParseException;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * 运单异常数据管理
 */
@Controller
@RequestMapping("/system/logisticserrorlog")
public class LogisticsErrorLogController extends BaseController{

    @Resource
    private ILogisticsErrorLogService logisticsErrorLogService;

    @RequestMapping("/index.htm")
    public String index(){
        return "system/logisticserrorlog/index";
    }

    @RequestMapping("/list")
    public Result list(LogisticsErrorLogListReq form){
        Page page = Page.getInstance(form);
        LogisticsErrorList list = new LogisticsErrorList();
        PageResultBO<LogisticsErrorLog> resultBO;
        Date signTime = null;
        Map param = new HashMap();
        try {
            if(!StringUtils.isEmpty(form.getSignTime())){
                signTime = DateUtil.str2date(form.getSignTime(),DateUtil.YEAR_AND_MONTH_FORMAT);
            }else{
                signTime = new Date();
            }
            BeanUtils.copyProperties(list,form);
            param.put("list",list);
            page.setParams(param);
            resultBO = logisticsErrorLogService.listByPage(signTime,page);
        } catch (Exception e) {
            logger.error(e.getMessage());
            throw new BaseException("系统异常");
        }
        return getSuccessResult(resultBO);
    }

    @RequestMapping("/reannalyze")
    public Result reannalyze(Long id,String month){
        Date singTime = null;
        try {
            singTime = DateUtil.str2date(month,DateUtil.YEAR_AND_MONTH_FORMAT);
            LogisticsErrorLog logisticsErrorLog = this.logisticsErrorLogService.getById(singTime,id);
            if(logisticsErrorLog!=null){
                LogisticsData logisticsData = logisticsErrorLog.getLogisticsData();
                if(logisticsData!=null){

                }
            }
             return this.getSuccessResult();
        } catch (ParseException e) {
            logger.error(e.getMessage(),e);
        }
        return this.getSuccessResult();
     }

}
